package com.flame.user.controller;

import com.flame.auth.core.annotation.HasAuth;
import com.flame.core.protocol.PageResult;
import com.flame.core.protocol.Result;
import com.flame.user.controller.vo.ObjAuthMaintainVo;
import com.flame.user.controller.vo.ObjAuthVo;
import com.flame.user.service.ObjAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * flame_obj_auth 对象权限表
 *
 * @author 吴欣童
 * @since 2022-12-26 15:40:05
 */
@RestController
public class ObjAuthController {

    @Autowired
    private ObjAuthService objAuthService;

    @HasAuth("auth")
    @PostMapping("/obj/auth/page")
    public PageResult pageObjAuth(@RequestBody ObjAuthVo objAuthVo) {
        return PageResult.success(objAuthService.pageObjAuth(objAuthVo));
    }

    @HasAuth("auth:edit")
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/obj/auth/maintain")
    public Result addObjAuth(@RequestBody @Validated ObjAuthMaintainVo objAuthMaintainVo) {
        objAuthService.addObjAuth(objAuthMaintainVo);
        return Result.success();
    }
}
